import { Pipe, PipeTransform } from '@angular/core';

export type SafeAny = any;


@Pipe({
  name: 'ellipsisPipe',
  standalone: true
})
export class EllipsisPipePipe implements PipeTransform {

  transform(value: SafeAny, length?: number, suffix: string = ''): SafeAny {
    if (typeof value !== 'string') {
      return value;
    }

    const len = typeof length === 'undefined' ? value.length : length;

    if (value.length <= len) {
      return value;
    }

    return value.substring(0, len) + suffix;
  }

}
